<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Group;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GroupController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Group(['spellUser','spellGoods']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('spellUser.nickName','昵称');
            $grid->column('order_id', '订单')->display(function ($e) {
                return $e == 1 ? '已生成' : '未生成';
            });
            $grid->column('total_num','商品总  数量');
            $grid->column('total_price','商品总金额');
            $grid->column('spellGoods.goods_name','商品名称');
            $grid->column('people');
            $grid->column('price');
            $grid->column('add_time');
            $grid->column('stop_time','结束时间');
            $grid->column('k_id', '是否是团长')->display(function ($e) {
                return $e == 1 ? '是' : '否';
            });
            $grid->column('is_refund', '用户退款情况')->display(function ($e) {
                return $e == 1 ? '已退款' : '未退款';
            });
            $grid->column('status','拼团状态');
            $grid->column('status', '拼团状态')->display(function ($e) {
                if($e==1){
                    return '拼团中';
                }elseif ($e==2){
                    return '已完成';
                }elseif ($e==3){
                    return '未完成';
                }
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Group(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('order_id');
            $show->field('order_id_key');
            $show->field('total_num');
            $show->field('total_price');
            $show->field('cid');
            $show->field('pid');
            $show->field('people');
            $show->field('price');
            $show->field('add_time');
            $show->field('stop_time');
            $show->field('k_id');
            $show->field('is_tpl');
            $show->field('is_refund');
            $show->field('status');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Group(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('order_id');
            $form->text('order_id_key');
            $form->text('total_num');
            $form->text('total_price');
            $form->text('cid');
            $form->text('pid');
            $form->text('people');
            $form->text('price');
            $form->text('add_time');
            $form->text('stop_time');
            $form->text('k_id');
            $form->text('is_tpl');
            $form->text('is_refund');
            $form->text('status');
        });
    }
}
